package com.rbac.web.model.req;

import com.rbac.web.model.Role;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.util.Optional;

/**
 * @author gengaoliu
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "角色添加参数")
public class RoleAddReq {
  @Schema(description = "名称")
  @NotNull(message = "角色名称不可为空")
  private String name;

  @Schema(description = "编码")
  private String code;

  @Schema(description = "是否启用")
  private Boolean enabled;

  @Schema(description = "描述")
  private String description;


  public Role toDomain() {
    return Role.builder()
        .name(name)
        .code(Optional.ofNullable(code).orElse(""))
        .disabled(Optional.ofNullable(enabled).orElse(Boolean.TRUE))
        .description(Optional.ofNullable(description).orElse(""))
        .build();
  }
}
